package demo04_other

import java.io.FileWriter
import scala.io.{BufferedSource, Source, StdIn}

object Demo01_readWriteFile {

  /**
   * 写文件
   */
  def writeFile() = {
    val fw: FileWriter = new FileWriter("E://test.txt",true)
    var line = ""
    for(i <- 1 to 5){
      line = StdIn.readLine("请输入内容：")
      fw.write(line+"\n")
      fw.flush()
    }
    fw.close()
  }

  /**
   * 读文件
   */
  def readFile() = {

    val file: BufferedSource = Source.fromFile("E://test.txt")
    file.getLines().toList.foreach(println)
    
    file.close()
  }

  def main(args: Array[String]): Unit = {
//    writeFile()
    readFile()
  }

}
